package xerr

var message map[int]string

const DefaultMsg = "服务器开小差啦,稍后再来试一试"

func init() {
	message = make(map[int]string)
	//	success
	message[OK] = "success"
	//	通用
	message[ServerError] = "服务繁忙，请稍后重试！"
	message[ParamError] = "参数错误"
	message[TokenError] = "token错误"
	message[TokenExpireError] = "token过期"
	message[TokenNotExistError] = "token不存在"
	message[TokenGenerateError] = "token生成失败"
	message[DBError] = "数据库错误"
	message[RdsError] = "redis错误"
	message[DbUpdateAffectedZeroError] = "数据库更新影响行数为0"

	message[UserExistError] = "用户已存在"
	message[UserNotExistError] = "用户不存在"
	message[UserPasswordError] = "用户密码错误"
	message[UserTelExistError] = "手机号已存在"
}

func MapErrMsg(code int) string {
	if msg, ok := message[code]; ok {
		return msg
	}
	return DefaultMsg
}

func IsCodeErr(code int) bool {
	if _, ok := message[code]; ok {
		return true
	} else {
		return false
	}
}
